export default (init = 10, action) => {
    switch (action.type) {
        case 'add':
            return init += action.payload;
        case 'sub':
            return init -= action.payload;
        default:
            return init;
    }
};

// 封装函数
// 加函数
export function addAction(payload) {
    return {
        type: 'add',
        payload
    }
}
// 减函数
export function subAction(payload) {
    return {
        type: 'sub',
        payload
    }
}

// 异步封装
export function asyncAddAction(payload) {
    return dispatch => {
        setTimeout(() => {
            dispatch(addAction(5))
        }, 1000);
    }
}

export function asyncSubAction(payload) {
    return dispatch => {
        setTimeout(() => {
            dispatch(subAction(6))
        }, 1000);
    }
}
